import { Injectable } from '@angular/core';
import * as _G6 from '@antv/g6';
@Injectable({
  providedIn: 'root',
})
export class DrawService {
  changeUniqueSelect(graph: _G6.Graph, item?: _G6.INode | _G6.IEdge): void {
    if (graph) {
      const allNodes = graph.getNodes();
      allNodes.forEach((node) => {
        if (!item || node.getID() !== item?.getID()) {
          const model = node.getModel();
          model.style.lineWidth = 1;
          node.update(model);
          node.draw();
        }
      });
      const allEdges = graph.getEdges();
      allEdges.forEach((edge) => {
        if (!item || edge.getID() !== item?.getID()) {
          graph.setItemState(edge, 'selected', false);
        }
      });
      const allCombos = graph.getCombos();
      allCombos.forEach(combo=>{
        if (!item || combo.getID() !== item?.getID()) {
          graph.setItemState(combo, 'selected', false);
        }
        const outerEdges = combo.getOutEdges();
        outerEdges.forEach(e=>{
           if(e && e.getID() !== item?.getID()){
            graph.setItemState(e, 'selected', false);
           }
        });
      });
    }
  }
}
